\documentclass[lang=cn,10pt]{elegantbook}
\title{第二次作业}
\author{陈冠宇 \ 3200102033}
\date{\today}
\logo{zju.png}
\cover{cover.jpg}
\usepackage{array}
\newcommand{\ccr}[1]{\makecell{{\color{#1}\rule{1cm}{1cm}}}}

\begin{document}
\maketitle
\subsection*{简介}
 实现判断用户输入是否为"yes"或"no"，若符合则分别回复"Good morning"和"Good afternoon"。若不符合则返回"Sorry, —— not recognized. Enter yes or no"，并要求用户继续输入，直至输入结果符合要求。
\subsection*{代码如下}
\begin{lstlisting}
#!/bin/sh

echo -n  "Is it morning? Please answer yes or no "
read timeofday

if   [ "$timeofday" = "yes" ]; then
    echo "Good morning"
elif [ "$timeofday" = "no" ]; then
    echo "Good afternoon"
else
    while [ "$timeofday" != "yes" ]&&[ "$timeofday" != "no" ];do
	echo "Sorry, $timeofday not recognized. Enter yes or no"
	read timeofday
    done
    if   [ "$timeofday" = "yes" ]; then
	echo "Good morning"
    elif [ "$timeofday" = "no" ]; then
	echo "Good afternoon"
    fi
fi

exit 0
\end{lstlisting}
\subsection*{小结}
用了条件判断和循环语句，其中多条件判断花了蛮多时间。初学时候有很多地方卡了很长时间，代码写得很丑！
\end{document}
